package com.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
/**
 * 统一返回结果
 */

@AllArgsConstructor
public class Result<T> {
    private boolean success;
    private int code ;
    private String msg;
    private  Object data;

    public boolean isSuccess() {
        return success;
    }

    public Result setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public int getCode() {
        return code;
    }

    public Result setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public Result() {

    }

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(boolean success, int code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;

    }

    public Result(boolean success, int code) {
        this.success = success;
        this.code = code;
    }

    public static <T> Result success(T data) {
        return new Result(true, 200, "success", data);
    }

    public static  Result success() {
        return new Result(true, 200, "请求成功");
    }

    public static Result success(String msg) {
        return new Result(true,200, msg);
    }

    public static Result fail(int code,String msg) {
        return new Result(false, code, msg, null);
    }

    public static Result fail(String msg) {
        return new Result(false, 404, msg, null);
    }

    public static Result fail() {
        return new Result(false, 404, "请求失败", null);
    }
}
